import cv2
capture=cv2.VideoCapture(0) #打开摄像头
while(capture.isOpened()):
    retval,image=capture.read() #读取帧
    cv2.imshow("Video",image)
    key=cv2.waitKey(1)  #窗口等待1ms
    if key==32:     #若按空格键，则退出循环
        break
capture.release()   #关闭摄像头
cv2.destroyAllWindows()